<?php
// Tim'Roster
// Copyright (c) 2011 Nicolas Nallet <aspgic2@gmail.com>
//
// This file is part of Tim'Roster.
//
// Tim'Roster is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Tim'Roster is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA

$xml_config = simplexml_load_file('config.xml');

include_once($_SERVER["DOCUMENT_ROOT"].$xml_config->roster_root_directory.'/data_access/item_DA.php');



abstract class Item_Base {



    const BASE_URL_ICON = 'http://atys.ryzom.com/api/item_icon.php?sheetid=';

    public static function search_item($type, $family, $code, $quality, $quality_com_signe){
        $item_DA = new item_DA();
        return $item_DA->search_item($type, $family, $code, $quality, $quality_com_signe);
    }

    /**
     * (PHP 5)<br/>
     * Construct a Item_Base instance
     * @param int $guild_id
     * @param int $id
     * @param string $code
     * @param string $name
     * @param int $quality
     * @param int $quantity
     * @param int $item_type_id
     * @param int $item_class
     * @param string $guild_name
     */
    public function Item_Base($guild_id, $id, $code, $name, $quality, $quantity, $item_type_id, $item_class, $guild_name){
        $this->id = $id;
        $this->code = $code;
        $this->guild_id = $guild_id;

        $this->guild_name = '';
        if (isset($guild_name)){
            $this->guild_name = $guild_name;
        }
        
        $this->name = $name;
        $this->quality = $quality;
        $this->quantity = $quantity;
        
        
        $this->item_class_id = $item_class;

        $this->item_type_id = $item_type_id;
    }

    protected $code;
    /**
     * (PHP 5)<br/>
     * Get item api code
     * @return string
     */
    public function get_code(){
        return $this->code;
    }

    protected $id;
    /**
     * (PHP 5)<br/>
     * Get item id. This id come from the database
     * @return int
     */
    public function get_id(){
        return $this->id;
    }

    protected $guild_id;
    /**
     * (PHP 5)<br/>
     * Get item guild id
     * @return int
     */
    public function get_guild_id(){
        return $this->guild_id;
    }

    protected $guild_name;
    /**
     * (PHP 5)<br/>
     * Get item guild name
     * @return string
     */
    public function get_guild_name(){
        return $this->guild_name;
    }

    protected $name;
    /**
     * (PHP 5)<br/>
     * Get item name
     * @return string
     */
    public function get_name(){
        return $this->name;
    }

    protected $item_class_id;
    /**
     * (PHP 5)<br/>
     * Get item class id 
     * @return int
     */
    public function get_item_class_id(){
        return $this->item_class_id;
    }
    /**
     * (PHP 5)<br/>
     * Get item class label
     * @return string
     */
    public function get_item_class_label(){
        return Enum_Item_Class::convert_id_to_label($this->item_class_id);
    }

    protected $quality;
    /**
     * (PHP 5)<br/>
     * Get item quality
     * @return int
     */
    public function get_quality(){
        return $this->quality;
    }

    protected $quantity;
    /**
     * (PHP 5)<br/>
     * Get item quantity
     * @return int
     */
    public function get_quantity(){
        return $this->quantity;
    }
    /**
     * (PHP 5)<br/>
     * Set item quantity
     * @param int $quantity
     */
    public function set_quantity($quantity){
        $this->quantity = $quantity;
    }

    protected $item_type_id;
    /**
     * (PHP 5)<br/>
     * Get item type id
     * @return int
     */
    public function get_item_type_id(){
        return $this->item_type_id;
    }
    /**
     * (PHP 5)<br/>
     * Get item type label
     * @return string
     */
    public function get_item_type_label(){
        return Enum_Item_Type::convert_id_to_label($this->item_type_id);
    }

    /**
     * (PHP 5)<br/>
     * Get item icon url
     * @return string
     */
    public function get_icon(){
        return Item_Base::BASE_URL_ICON.$this->code.'&q='.$this->quality.'&s='.$this->quantity;
    }

    /**
     * (PHP 5)<br/>
     * Get item order
     * @return int
     */
    abstract public function get_order();

    /**
     * (PHP 5)<br/>
     * Check if the item in parameter is the same as $this
     * @param Item_Base $item
     * @return bool
     */
    public function is_the_same_item(Item_Base $item){
        return (($this->get_code() == $item->get_code())
                && ($this->get_item_class_id() == $item->get_item_class_id())
                && ($this->get_quality() == $item->get_quality()));
    }
}
?>